<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户注册</title>
    <link rel="stylesheet" href="/static/css/register.css" type="text/css">
</head>
<body>
    <div class="container">
        <!-- 注册表单 -->
        <div class="form-container" id="registerForm">
            <form id="registerFormElement" method="post" action="/register" onsubmit="return validateForm()">
              <h2 class="title">用户注册</h2>
              {{if .error}}
              <div class="error-message" style="color: red; margin-bottom: 15px;">{{.error}}</div>
              {{end}}
              <div class="input-group">
                <label for="username">用户名</label>
                <input type="text" id="username" name="username" required>
            </div>  
            <div class="input-group">
                <label for="email">电子邮箱</label>
                <input type="email" id="email" name="email" required>
            </div>
            <div class="input-group">
                <label for="password">密码</label>
                <input type="password" id="password" name="password" required>
            </div>
            <div class="input-group">
                <label for="confirmPassword">确认密码</label>
                <input type="password" id="confirmPassword" name="confirmPassword" required>
            </div>
            <button type="submit" class="button">立即注册</button>
            <div class="toggle-form">
                已有账号? <a href="/login">立即登录</a>
            </div>
        </form>
    </div>   
    <script>
        function validateForm() {
            const password = document.getElementById('password').value;
            const confirmPassword = document.getElementById('confirmPassword').value;
            
            if (password !== confirmPassword) {
                alert('两次输入的密码不一致');
                return false;
            }
            return true;
        }
    </script>
</body>
</html>